function initialize() {
  var mapDiv = document.getElementById('map-canvas');
  var map = new google.maps.Map(mapDiv, {
    center: new google.maps.LatLng(37.777763, -122.403875),
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  google.maps.event.addListener(map, 'idle', function() {
    queryFlickr(map.getBounds(), flickrCallback);
  });
}

function queryFlickr(bounds, callback) {
  var sw = bounds.getSouthWest();
  var ne = bounds.getNorthEast();

  var bbox = [sw.lng(), sw.lat(), ne.lng(), ne.lat()].join(',');

  var requestUrl = [
    'http://api.flickr.com/services/rest/?method=flickr.photos.search',
    'api_key=' + FLICKR_API_KEY,
    'format=json',
    'jsoncallback=mashupFlickrCallback_',
    'accuracy=16',
    'has_geo=1',
    'per_page=50',
    'sort=date-posted-desc',
    'bbox=' + encodeURIComponent(bbox),
    'extras=geo,description,date_taken'
  ].join('&');

  window.mashupFlickrCallback_ = function(photos) {
    callback(photos);
  };

  getScript(requestUrl);
}

function flickrCallback(result) {
  console.log(result);
}

function getScript(src) {
  var script = document.createElement('script');
  script.src = src;
  document.head.appendChild(script);
}

var FLICKR_API_KEY = '1632c18a388a4da173db303dc5d20755';
